#coding: utf8

import web
import sessions
import utils

from config import admins

def auth(user, passwd):
    if user in admins and admins[user] == passwd:
        return True
    return False

def get_user():
    sid = web.cookies(sid = None)['sid']
    if not sid:
        return None
    sid = utils.filter_hex(sid)
    s = sessions.get(sid)
    if not s:
        return None
    return s['username']

def get_lang():
    # default lang
    lang = "en_us"

    sid = web.cookies(sid = None)['sid']
    if not sid:
        return lang 

    sid = utils.filter_hex(sid)
    s = sessions.get(sid)
    if not s:
        return lang

    lang = s['lang']
    if not lang:
        lang = "en_us"

    return lang

def get_sid():
    sid = web.cookies(sid = None)['sid']
    return sid
